﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoCharacter : SignedApiCall
    {
        public ApiCharacter Character { get; private set; }
        public IEnumerable<ApiMission> Missions { get; private set; }

        public ApiInfoCharacter()
        {
        }

        public ApiInfoCharacter(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int characterId)
        {
            LoadSignedApiCall("c=" + characterId.ToString());
            XmlNodeList characterNodes = XmlDocument.GetElementsByTagName("a:get_characters_feed_statsResult");
            if (characterNodes.Count > 0)
            {
                Character = new ApiCharacter(characterNodes[0].CreateNavigator().ReadSubtree());
                XmlNodeList missionNodes = XmlDocument.GetElementsByTagName("a:get_character_mission_statsResult");
                List<ApiMission> missions = new List<ApiMission>();

                foreach (XmlNode missionNode in missionNodes)
                {
                    missions.Add(new ApiMission(missionNode.CreateNavigator().ReadSubtree()));
                }
                Missions = missions;
            }
        }

        protected override string ApiCallName
        {
            get { return "Character"; }
        }
    }
}
